<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <div>请问你一个yes或no的问题</div>
        <input type="text" v-model="question">
        <div>答案 {{ answer }}</div>
    </div>
    <script src="./node_modules/vue/dist/vue.js"></script>
    <script>
        new Vue({
            el: '#app',
            data: {
                question: '',
                answer: ''
            },
            watch: {
                question() {
                    // 检测输入的问题 一旦发现输入？就给出答案
                    if(this.question.indexOf('?') !== -1 || this.question.includes('？')) {
                        this.answer = Math.random() > 0.5 ? 'yes': 'no'
                    } else {
                        this.answer = ''
                    }
                }
            }
        })
    </script>
</body>
</html>